<?php

class UserMeta extends ActiveRecordBase
{
	public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }

	public function tableName() {
		return "{{usermeta}}";
	}

	public function relations() {
		return array(
			'user' => array(self::BELONGS_TO, 'User', 'user_id'),
		);
	}

	public function rules()
	{
		return array(
			array('user_id', 'required'),
			array('meta_key, meta_value', 'safe'),
		);
	}
	
	public function beforeSave() {
		$this->meta_value = maybe_serialize($this->meta_value);

		return true;
	}
	
	public function afterSave() {
		$this->meta_value = maybe_unserialize($this->meta_value);
	}
	
	public function afterFind() {
		$this->meta_value = maybe_unserialize($this->meta_value);
	}

}